From 6aeed243e67749a3b95c160103148b4982c2f0a4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Jul 2017 21:46:06 +0300 Subject: [PATCH] Unify naming for `package_root` --- src/cargo/util/toml/mod.rs | 26 +++++++++++++------------- src/cargo/util/toml/targets.rs | 32 ++++++++++++++++---------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 82bdfad60..e7772daa6 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -39,7 +39,7 @@ fn do_read_manifest(contents: &str, source_id: &SourceId, config: &Config) -> CargoResult<(EitherManifest, Vec)> { - let project_root = manifest_file.parent().unwrap(); + let package_root = manifest_file.parent().unwrap(); let toml = { let pretty_filename = @@ -57,7 +57,7 @@ fn do_read_manifest(contents: &str, let manifest = Rc::new(manifest); return match TomlManifest::to_real_manifest(&manifest, source_id, - project_root, + package_root, config) { Ok((mut manifest, paths)) => { for key in unused { @@ -73,7 +73,7 @@ fn do_read_manifest(contents: &str, Err(e) => { match TomlManifest::to_virtual_manifest(&manifest, source_id, - project_root, + package_root, config) { Ok((m, paths)) => Ok((EitherManifest::Virtual(m), paths)), Err(..) => Err(e), @@ -496,7 +496,7 @@ impl TomlManifest { fn to_real_manifest(me: &Rc, source_id: &SourceId, - project_root: &Path, + package_root: &Path, config: &Config) -> CargoResult<(Manifest, Vec)> { let mut nested_paths = vec![]; @@ -507,8 +507,8 @@ impl TomlManifest { CargoError::from("no `package` or `project` section found.") })?; - let project_name = project.name.trim(); - if project_name.is_empty() { + let package_name = project.name.trim(); + if package_name.is_empty() { bail!("package name cannot be an empty string.") } @@ -517,13 +517,13 @@ impl TomlManifest { // If we have no lib at all, use the inferred lib if available // If we have a lib with a path, we're done // If we have a lib with no path, use the inferred lib or_else package name - let targets = targets(me, project_name, project_root, &project.build)?; + let targets = targets(me, package_name, package_root, &project.build)?; if targets.is_empty() { debug!("manifest has no build targets"); } - if let Err(e) = unique_build_targets(&targets, project_root) { + if let Err(e) = unique_build_targets(&targets, package_root) { warnings.push(format!("file found to be present in multiple \ build targets: {}", e)); } @@ -541,7 +541,7 @@ impl TomlManifest { config: config, warnings: &mut warnings, platform: None, - root: project_root, + root: package_root, }; fn process_dependencies( @@ -752,9 +752,9 @@ impl TomlManifest { fn maybe_custom_build(&self, build: &Option, - project_dir: &Path) + package_root: &Path) -> Option { - let build_rs = project_dir.join("build.rs"); + let build_rs = package_root.join("build.rs"); match *build { Some(StringOrBool::Bool(false)) => None, // explicitly no build script Some(StringOrBool::Bool(true)) => Some(build_rs.into()), @@ -773,9 +773,9 @@ impl TomlManifest { /// Will check a list of build targets, and make sure the target names are unique within a vector. /// If not, the name of the offending build target is returned. -fn unique_build_targets(targets: &[Target], project_root: &Path) -> Result<(), String> { +fn unique_build_targets(targets: &[Target], package_root: &Path) -> Result<(), String> { let mut seen = HashSet::new(); - for v in targets.iter().map(|e| project_root.join(e.src_path())) { + for v in targets.iter().map(|e| package_root.join(e.src_path())) { if !seen.insert(v.clone()) { return Err(v.display().to_string()); } diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index d5ec3a96d..dcd9786d4 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -21,11 +21,11 @@ use super::{TomlTarget, LibKind, PathValue, TomlManifest, StringOrBool, pub fn targets(manifest: &TomlManifest, - project_name: &str, - project_root: &Path, + package_name: &str, + package_root: &Path, custom_build: &Option) -> CargoResult> { - let layout = Layout::from_project_path(project_root); + let layout = Layout::from_package_path(package_root); let lib = match manifest.lib { Some(ref lib) => { @@ -33,7 +33,7 @@ pub fn targets(manifest: &TomlManifest, lib.validate_crate_type()?; Some( TomlTarget { - name: lib.name.clone().or(Some(project_name.to_owned())), + name: lib.name.clone().or(Some(package_name.to_owned())), path: lib.path.clone().or_else( || layout.lib.as_ref().map(|p| PathValue(p.clone())) ), @@ -41,7 +41,7 @@ pub fn targets(manifest: &TomlManifest, } ) } - None => inferred_lib_target(project_name, &layout), + None => inferred_lib_target(package_name, &layout), }; let bins = match manifest.bin { @@ -51,7 +51,7 @@ pub fn targets(manifest: &TomlManifest, }; bins.clone() } - None => inferred_bin_targets(project_name, &layout) + None => inferred_bin_targets(package_name, &layout) }; for bin in bins.iter() { @@ -138,30 +138,30 @@ struct Layout { impl Layout { /// Returns a new `Layout` for a given root path. - /// The `root_path` represents the directory that contains the `Cargo.toml` file. - fn from_project_path(root_path: &Path) -> Layout { + /// The `package_root` represents the directory that contains the `Cargo.toml` file. + fn from_package_path(package_root: &Path) -> Layout { let mut lib = None; let mut bins = vec![]; let mut examples = vec![]; let mut tests = vec![]; let mut benches = vec![]; - let lib_candidate = root_path.join("src").join("lib.rs"); + let lib_candidate = package_root.join("src").join("lib.rs"); if fs::metadata(&lib_candidate).is_ok() { lib = Some(lib_candidate); } - try_add_file(&mut bins, root_path.join("src").join("main.rs")); - try_add_files(&mut bins, root_path.join("src").join("bin")); - try_add_mains_from_dirs(&mut bins, root_path.join("src").join("bin")); + try_add_file(&mut bins, package_root.join("src").join("main.rs")); + try_add_files(&mut bins, package_root.join("src").join("bin")); + try_add_mains_from_dirs(&mut bins, package_root.join("src").join("bin")); - try_add_files(&mut examples, root_path.join("examples")); + try_add_files(&mut examples, package_root.join("examples")); - try_add_files(&mut tests, root_path.join("tests")); - try_add_files(&mut benches, root_path.join("benches")); + try_add_files(&mut tests, package_root.join("tests")); + try_add_files(&mut benches, package_root.join("benches")); return Layout { - root: root_path.to_path_buf(), + root: package_root.to_path_buf(), lib: lib, bins: bins, examples: examples, -- 2.30.2